﻿// <copyright file="AppNotificationRecipient.cs" company="Robert Venables">
// Copyright (c) 2009 Robert Venables.
// </copyright>
// <author>Robert Venables</author>
// <email>rob@rvenables.com</email>

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace VNotify
{
    /// <summary>
    /// A recipient capable of receiving notifications.
    /// </summary>
    [System.Serializable]
    public class AppNotificationRecipient
    {
        /// <summary>
        /// Initializes a new instance of the AppNotificationRecipient class
        /// with a specified API key.
        /// </summary>
        /// <param name="apiKey">Required API key (Identifying the recipient).</param>
        public AppNotificationRecipient(string apiKey)
        {
            this.SetValidateAPIKey(apiKey);
        }

        /// <summary>
        /// Initializes a new instance of the AppNotificationRecipient class
        /// with a specified API key and name..
        /// </summary>
        /// <param name="name">Friendly name for the recipient.</param>
        /// <param name="apiKey">Required API key (Identifying the recipient).</param>
        public AppNotificationRecipient(string name, string apiKey)
        {
            if (name == null)
                throw new ArgumentException("Invalid Name");

            this.Name = name;

            this.SetValidateAPIKey(apiKey);
        }

        /// <summary>
        /// Gets or sets the ptional friendly nickname for the recipient.
        /// </summary>
        public string Name { get; set; }

        /// <summary>
        /// Gets the required API key that identifies the recipient.
        /// </summary>
        public string ApiKey { get; private set; }

        /// <summary>
        /// Validates an API key (setting the ApiKey field if successful).
        /// </summary>
        /// <param name="apiKey">The API key to validate and set.</param>
        private void SetValidateAPIKey(string apiKey) 
        {
            if (string.IsNullOrEmpty(apiKey) || apiKey.Length < 4)
                throw new ArgumentException("Invalid API Key!");

            this.ApiKey = apiKey;
        }
    }
}
